package com.fenghen.demo01.aspect;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;


@Configuration
@Aspect
@EnableAspectJAutoProxy
public class LogExecutionTimeAspect {
    private static final Logger logger = LoggerFactory.getLogger(LogExecutionTimeAspect.class);

    @Around("@annotation(com.fenghen.demo01.annotation.LogExecutionTime)") // 监听@LogExecutionTime注解
    public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();

        Object proceed = joinPoint.proceed(); // 执行被注解的方法

        long executionTime = System.currentTimeMillis() - start;

        logger.info("Method {} executed in {} ms", joinPoint.getSignature(), executionTime);
        logger.error("光的传说");
        return proceed;
    }

}
